
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Kubernetes · GitBook笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="chenjiebin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="../tool/gradle.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../document/kubernetes/kubernetes.html">
            
                <a href="../document/kubernetes/kubernetes.html">
            
                    
                    Kubernetes英文教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../document/kubernetes/kubernetes.html">
            
                <a href="../document/kubernetes/kubernetes.html#concepts">
            
                    
                    Kubernetes Concepts
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="../document/kubernetes/concepts/overview.html">
            
                <a href="../document/kubernetes/concepts/overview.html">
            
                    
                    Kubernetes Overview
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="../document/kubernetes/concepts/components.html">
            
                <a href="../document/kubernetes/concepts/components.html">
            
                    
                    Kubernetes Components
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="../document/kubernetes/concepts/nodes.html">
            
                <a href="../document/kubernetes/concepts/nodes.html">
            
                    
                    Kubernetes Nodes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../document/kubernetes/kubernetes.html">
            
                <a href="../document/kubernetes/kubernetes.html#tutorial">
            
                    
                    Kubernetes Tutorial
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../document/kubernetes/tutorial/kubernetes-basics.html">
            
                <a href="../document/kubernetes/tutorial/kubernetes-basics.html">
            
                    
                    Kubernetes Basics
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../java/java.html">
            
                <a href="../java/java.html">
            
                    
                    Java基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../java/java-summary.html">
            
                <a href="../java/java-summary.html">
            
                    
                    Java_Summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../java/java-jvm.html">
            
                <a href="../java/java-jvm.html">
            
                    
                    Java_JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../java/effectiveJava.html">
            
                <a href="../java/effectiveJava.html">
            
                    
                    effectiveJava
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../java/design-pattern.html">
            
                <a href="../java/design-pattern.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../java/JavaTest.html">
            
                <a href="../java/JavaTest.html">
            
                    
                    JavaTest
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../java/myframe.html">
            
                <a href="../java/myframe.html">
            
                    
                    MyFrame
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../database/database.html">
            
                <a href="../database/database.html">
            
                    
                    数据库基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../database/mysql.html">
            
                <a href="../database/mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../database/redis.html">
            
                <a href="../database/redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../database/kingbase.html">
            
                <a href="../database/kingbase.html">
            
                    
                    KingBase
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../database/polardb.html">
            
                <a href="../database/polardb.html">
            
                    
                    PolarDB
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../system/system.html">
            
                <a href="../system/system.html">
            
                    
                    环境配置工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../system/nodejs.html">
            
                <a href="../system/nodejs.html">
            
                    
                    Node.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../system/gitbook.html">
            
                <a href="../system/gitbook.html">
            
                    
                    Gitbook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../system/linux.html">
            
                <a href="../system/linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../system/kylin.html">
            
                <a href="../system/kylin.html">
            
                    
                    麒麟系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../tool/tool.html">
            
                <a href="../tool/tool.html">
            
                    
                    开发工具介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../tool/docker.html">
            
                <a href="../tool/docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../tool/idea.html">
            
                <a href="../tool/idea.html">
            
                    
                    Idea
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../tool/maven.html">
            
                <a href="../tool/maven.html">
            
                    
                    Maven
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../tool/gradle.html">
            
                <a href="../tool/gradle.html">
            
                    
                    Gradle
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.5" data-path="kubernate.html">
            
                <a href="kubernate.html">
            
                    
                    Kubernetes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Kubernetes</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#kubernetes-&#x6982;&#x5FF5;"><b>1.1. </b>Kubernetes &#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#kubernetes-&#x67B6;&#x6784;"><b>1.2. </b>Kubernetes &#x67B6;&#x6784;</a></li><li><span class="title-icon "></span><a href="#kubernetes-&#x5B89;&#x88C5;"><b>1.3. </b>Kubernetes &#x5B89;&#x88C5;</a></li><ul><li><span class="title-icon "></span><a href="#&#x6267;&#x884C;&#x811A;&#x672C;"><b>1.3.1. </b>&#x6267;&#x884C;&#x811A;&#x672C;</a></li><li><span class="title-icon "></span><a href="#wsl2"><b>1.3.2. </b>wsl2</a></li></ul><li><span class="title-icon "></span><a href="#dashboard-&#x9762;&#x677F;"><b>1.4. </b>Dashboard &#x9762;&#x677F;</a></li><li><span class="title-icon "></span><a href="#kubernetes-&#x547D;&#x4EE4;"><b>1.5. </b>Kubernetes &#x547D;&#x4EE4;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4E0E;docker&#x76F8;&#x5173;&#x7684;&#x547D;&#x4EE4;"><b>1.5.1. </b>&#x4E0E;docker&#x76F8;&#x5173;&#x7684;&#x547D;&#x4EE4;</a></li><li><span class="title-icon "></span><a href="#&#x547D;&#x540D;&#x7A7A;&#x95F4;"><b>1.5.2. </b>&#x547D;&#x540D;&#x7A7A;&#x95F4;</a></li><li><span class="title-icon "></span><a href="#kubectl-&#x4E0A;&#x4E0B;&#x6587;&#x548C;&#x914D;&#x7F6E;"><b>1.5.3. </b>kubectl &#x4E0A;&#x4E0B;&#x6587;&#x548C;&#x914D;&#x7F6E;</a></li><li><span class="title-icon "></span><a href="#&#x521B;&#x5EFA;&#x5BF9;&#x8C61;"><b>1.5.4. </b>&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</a></li><li><span class="title-icon "></span><a href="#&#x663E;&#x793A;&#x548C;&#x67E5;&#x627E;&#x8D44;&#x6E90;"><b>1.5.5. </b>&#x663E;&#x793A;&#x548C;&#x67E5;&#x627E;&#x8D44;&#x6E90;</a></li><li><span class="title-icon "></span><a href="#&#x5220;&#x9664;&#x8D44;&#x6E90;"><b>1.5.6. </b>&#x5220;&#x9664;&#x8D44;&#x6E90;</a></li><li><span class="title-icon "></span><a href="#&#x8D44;&#x6E90;&#x7C7B;&#x578B;"><b>1.5.7. </b>&#x8D44;&#x6E90;&#x7C7B;&#x578B;</a></li></ul><li><span class="title-icon "></span><a href="#&#x63A7;&#x5236;&#x5668;"><b>1.6. </b>&#x63A7;&#x5236;&#x5668;</a></li><ul><li><span class="title-icon "></span><a href="#rcrs"><b>1.6.1. </b>RC/RS</a></li><li><span class="title-icon "></span><a href="#deployment"><b>1.6.2. </b>Deployment</a></li></ul><li><span class="title-icon "></span><a href="#kubernetes-&#x5E94;&#x7528;"><b>1.7. </b>Kubernetes &#x5E94;&#x7528;</a></li><li><span class="title-icon "></span><a href="#ingress"><b>1.8. </b>Ingress</a></li><li><span class="title-icon "></span><a href="#&#x53C2;&#x8003;&#x6587;&#x6863;"><b>1.9. </b>&#x53C2;&#x8003;&#x6587;&#x6863;</a></li></ul></ul></div><a href="#" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h2 id="kubernetes-&#x6982;&#x5FF5;"><a name="kubernetes-&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. Kubernetes &#x6982;&#x5FF5;</h2>
<p>Kubernetes &#x662F;&#x4E00;&#x4E2A;&#x8DE8;&#x591A;&#x4E3B;&#x673A;&#x7684;&#x5BB9;&#x5668;&#x7F16;&#x6392;&#x5E73;&#x53F0;&#xFF0C;&#x5B83;&#x4F7F;&#x7528;&#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#x5C06;&#x591A;&#x4E2A;&#x4E3B;&#x673A;&#xFF08;&#x7269;&#x7406;&#x673A;&#x6216;&#x865A;&#x62DF;&#x673A;&#xFF09;&#x6784;&#x6210;&#x7EDF;&#x4E00;&#x7684;&#x96C6;&#x7FA4;</p>
<blockquote>
<p>Cluster</p>
</blockquote>
<p>Cluster &#x662F;&#x8BA1;&#x7B97;&#x3001;&#x5B58;&#x50A8;&#x548C;&#x7F51;&#x7EDC;&#x8D44;&#x6E90;&#x7684;&#x96C6;&#x5408;&#xFF0C;kubernetes &#x5229;&#x7528;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#x8FD0;&#x884C;&#x5404;&#x79CD;&#x57FA;&#x4E8E;&#x5BB9;&#x5668;&#x7684;&#x5E94;&#x7528;</p>
<blockquote>
<p>Master</p>
</blockquote>
<p>Master &#x662F; Cluster &#x7684;&#x5927;&#x8111;&#xFF0C;&#x8D1F;&#x8D23;&#x8C03;&#x5EA6;
Master &#x662F;&#x96C6;&#x7FA4;&#x7684;&#x7F51;&#x5173;&#x548C;&#x4E2D;&#x67A2;&#xFF0C;&#x8D1F;&#x8D23;&#x4E3A;&#x7528;&#x6237;&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x66B4;&#x9732;API</p>
<blockquote>
<p>Node</p>
</blockquote>
<p>Node &#x7684;&#x804C;&#x8D23;&#x662F;&#x8FD0;&#x884C;&#x5BB9;&#x5668;&#x5E94;&#x7528;&#xFF0C;&#x7531; Master &#x8D1F;&#x8D23;&#x76D1;&#x63A7;&#x5E76;&#x6C47;&#x62A5;&#x5BB9;&#x5668;&#x7684;&#x72B6;&#x6001;</p>
<blockquote>
<p>Pod</p>
</blockquote>
<p>Pod &#x662F; Kubernetes &#x7684;&#x6700;&#x5C0F;&#x5DE5;&#x4F5C;&#x5355;&#x5143;&#x3002;&#x6BCF;&#x4E2A; Pod &#x5305;&#x542B;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x5BB9;&#x5668;</p>
<p>Pod &#x4E2D;&#x7684;&#x5BB9;&#x5668;&#x4F1A;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x6574;&#x4F53;&#x88AB; Master &#x8C03;&#x5EA6;&#x5230;&#x4E00;&#x4E2A; Node &#x4E0A;&#x8FD0;&#x884C;</p>
<p>Pod &#x5185;&#x90E8;&#x6240;&#x6709;&#x5BB9;&#x5668;&#x5171;&#x4EAB;&#x901A;&#x4FE1;&#x7F51;&#x7EDC;&#x548C;&#x5B58;&#x50A8;&#x8D44;&#x6E90;</p>
<blockquote>
<p>Controller</p>
</blockquote>
<p>Controller &#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x548C;&#x7BA1;&#x7406;&#x591A;&#x4E2A; Pod&#xFF0C;&#x63D0;&#x4F9B;&#x526F;&#x672C;&#x7BA1;&#x7406;&#x3001;&#x6EDA;&#x52A8;&#x5347;&#x7EA7;&#x548C;&#x96C6;&#x7FA4;&#x7EA7;&#x522B;&#x7684;&#x81EA;&#x6108;&#x80FD;&#x529B;</p>
<ul>
<li>Deployment &#x6700;&#x5E38;&#x7528;&#x7684; Controller</li>
<li>ReplicaSet &#x591A;&#x526F;&#x672C;&#x7BA1;&#x7406;</li>
<li>DaemonSet &#x7528;&#x4E8E;&#x6BCF;&#x4E2A; Node &#x6700;&#x591A;&#x53EA;&#x8FD0;&#x884C;&#x4E00;&#x4E2A; Pod &#x526F;&#x672C;&#x7684;&#x573A;&#x666F;</li>
<li>StatefuleSet &#x80FD;&#x591F;&#x4FDD;&#x8BC1;&#x6BCF;&#x4E2A; Pod &#x7684;&#x6BCF;&#x4E2A;&#x526F;&#x672C;&#x5728;&#x6574;&#x4E2A;&#x751F;&#x547D;&#x5468;&#x671F;&#x4E2D;&#x540D;&#x79F0;&#x4E0D;&#x53D8;</li>
<li>Job &#x7528;&#x4E8E;&#x8FD0;&#x884C;&#x7ED3;&#x675F;&#x5C31;&#x5220;&#x9664;&#x7684;&#x5E94;&#x7528;</li>
</ul>
<blockquote>
<p>Service</p>
</blockquote>
<p>Service &#x5B9A;&#x4E49;&#x4E86;&#x5916;&#x754C;&#x8BBF;&#x95EE;&#x4E00;&#x7EC4;&#x7279;&#x5B9A; Pod &#x7684;&#x65B9;&#x5F0F;&#xFF0C;Service &#x6709;&#x81EA;&#x5DF1;&#x7684; IP &#x548C;&#x7AEF;&#x53E3;&#xFF0C;Service &#x4E3A; Pod &#x63D0;&#x4F9B;&#x4E86;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#xFF0C;&#x7528;&#x6765;&#x8BBF;&#x95EE; Pod</p>
<blockquote>
<p>Namespace</p>
</blockquote>
<p>Namespace &#x53EF;&#x4EE5;&#x5C06;&#x4E00;&#x4E2A;&#x7269;&#x7406;&#x7684; Cluster &#x903B;&#x8F91;&#x4E0A;&#x5212;&#x5206;&#x6210;&#x591A;&#x4E2A;&#x865A;&#x62DF; Cluster&#xFF0C;&#x6BCF;&#x4E2A; Cluster &#x5C31;&#x662F;&#x4E00;&#x4E2A; NameSpace</p>
<p>&#x4E0D;&#x540C; NameSpace &#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x662F;&#x5B8C;&#x5168;&#x9694;&#x79BB;&#x7684;</p>
<h2 id="kubernetes-&#x67B6;&#x6784;"><a name="kubernetes-&#x67B6;&#x6784;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x67B6;&#x6784;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. Kubernetes &#x67B6;&#x6784;</h2>
<h2 id="kubernetes-&#x5B89;&#x88C5;"><a name="kubernetes-&#x5B89;&#x88C5;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x5B89;&#x88C5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. Kubernetes &#x5B89;&#x88C5;</h2>
<ul>
<li>&#x5728; windows &#x5B89;&#x88C5; Docker Desktop &#x5E76;&#x4FEE;&#x8BE5;&#x955C;&#x50CF;&#x5730;&#x5740;</li>
<li>&#x67E5;&#x770B; Desktop &#x53CA;&#x5BF9;&#x5E94; k8s &#x5BF9;&#x5E94;&#x7248;&#x672C;</li>
<li>&#x4E0B;&#x8F7D;&#x6267;&#x884C;&#x811A;&#x672C; k8s-for-docker-desktop &#x5BF9;&#x5E94;&#x7248;&#x672C;</li>
<li>&#x7BA1;&#x7406;&#x5458;&#x6253;&#x5F00; powershell &#x6267;&#x884C;&#x811A;&#x672C;</li>
<li>&#x914D;&#x7F6E; wsl &#x914D;&#x7F6E;&#x6587;&#x4EF6;</li>
<li>&#x542F;&#x7528; kubernetes</li>
</ul>
<h3 id="&#x6267;&#x884C;&#x811A;&#x672C;"><a name="&#x6267;&#x884C;&#x811A;&#x672C;" class="anchor-navigation-ex-anchor" href="#&#x6267;&#x884C;&#x811A;&#x672C;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.1. &#x6267;&#x884C;&#x811A;&#x672C;</h3>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x4E0B;&#x8F7D;&#x5BF9;&#x5E94;&#x7248;&#x672C;&#x7684;&#x6267;&#x884C;&#x547D;&#x4EE4; -- &#x5FC5;&#x987B;&#x6CE8;&#x610F; k8s &#x548C; load_images.ps1 &#x7684;&#x7248;&#x672C;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;</span>
<span class="token function">git</span> clone git@gitee.com:blue_star/k8s-for-docker-desktop.git <span class="token parameter variable">-b</span> v1.28.2
<span class="token comment"># &#x5F00;&#x542F;&#x7B56;&#x7565; -- &#x7BA1;&#x7406;&#x5458;&#x8FD0;&#x884C; Powershell &#x6267;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;</span>
Set-ExecutionPolicy RemoteSigned
Y
<span class="token comment"># &#x6267;&#x884C;&#x811A;&#x672C;</span>
.<span class="token punctuation">\</span>load_images.ps1
<span class="token comment"># &#x5173;&#x95ED;&#x7B56;&#x7565;</span>
Set-ExecutionPolicy Restricted
Y
</code></pre>
<blockquote>
<p>&#x914D;&#x7F6E; <code>C:\Users\username\.wslconfig</code></p>
</blockquote>
<p>&#x9700;&#x8981;&#x914D;&#x7F6E; .wslconfig &#x6765;&#x6269;&#x5145;&#x4F7F;&#x7528;&#x7A7A;&#x95F4;</p>
<pre class="language-"><code># &#x542F;&#x7528; Docker Desktop &#x4E2D;&#x7684; kubernetes &#x9700;&#x8981;&#x5F88;&#x5927;&#x5185;&#x5B58;
# &#x9700;&#x8981;wsl2&#x7248;&#x672C;
[wsl2]
# &#x8BBE;&#x7F6E;&#x5185;&#x5B58;
memory=8GB 
# &#x8BBE;&#x7F6E;&#x5904;&#x7406;&#x5668;
processors=4
# &#x8BBE;&#x7F6E;&#x4EA4;&#x6362;&#x7A7A;&#x95F4;
swap=4GB
</code></pre><h3 id="wsl2"><a name="wsl2" class="anchor-navigation-ex-anchor" href="#wsl2"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2. wsl2</h3>
<p>WSL &#x662F;&#x9002;&#x7528;&#x4E8E; Linux &#x7684; Windows &#x5B50;&#x7CFB;&#x7EDF;</p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x67E5;&#x770B;&#x7248;&#x672C;</span>
wsl <span class="token parameter variable">-l</span> <span class="token parameter variable">-v</span>
<span class="token comment"># &#x6D4F;&#x89C8;&#x5668;&#x8BBF;&#x95EE;&#x67E5;&#x770B; wsl .vhdx &#x6587;&#x4EF6;</span>
<span class="token punctuation">\</span><span class="token punctuation">\</span>wsl$<span class="token punctuation">\</span>docker-desktop
<span class="token punctuation">\</span><span class="token punctuation">\</span>wsl$<span class="token punctuation">\</span>docker-desktop-data
</code></pre>
<h2 id="dashboard-&#x9762;&#x677F;"><a name="dashboard-&#x9762;&#x677F;" class="anchor-navigation-ex-anchor" href="#dashboard-&#x9762;&#x677F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. Dashboard &#x9762;&#x677F;</h2>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x5B89;&#x88C5; dashboard</span>
kubectl apply <span class="token parameter variable">-f</span> https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
kubectl apply <span class="token parameter variable">-f</span> https://github.com/kubernetes/dashboard/blob/v2.7.0/aio/deploy/recommended.yaml
kubectl apply <span class="token parameter variable">-f</span> recommended.yaml
<span class="token comment"># &#x5F00;&#x542F;&#x670D;&#x52A1;</span>
kubectl proxy
<span class="token comment"># &#x9875;&#x9762;&#x8BBF;&#x95EE;</span>
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/<span class="token comment">#/login</span>
<span class="token comment"># &#x6388;&#x6743; kube-system &#x9ED8;&#x8BA4;&#x670D;&#x52A1;&#x8D26;&#x53F7;</span>
kubectl apply <span class="token parameter variable">-f</span> kube-system-default.yaml
<span class="token comment"># &#x83B7;&#x53D6; token</span>
kubectl <span class="token parameter variable">-n</span> kube-system describe secret default
</code></pre>
<h2 id="kubernetes-&#x547D;&#x4EE4;"><a name="kubernetes-&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. Kubernetes &#x547D;&#x4EE4;</h2>
<h3 id="&#x4E0E;docker&#x76F8;&#x5173;&#x7684;&#x547D;&#x4EE4;"><a name="&#x4E0E;docker&#x76F8;&#x5173;&#x7684;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#&#x4E0E;docker&#x76F8;&#x5173;&#x7684;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.1. &#x4E0E;docker&#x76F8;&#x5173;&#x7684;&#x547D;&#x4EE4;</h3>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x67E5;&#x770B;&#x7248;&#x672C;</span>
<span class="token function">docker</span> version
kubectl version
<span class="token comment"># &#x67E5;&#x770B;&#x914D;&#x7F6E;</span>
<span class="token function">docker</span> info
kubectl cluster-info
<span class="token comment"># &#x521B;&#x5EFA;&#x5BB9;&#x5668;</span>
<span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">-e</span> <span class="token assign-left variable">DOMAIN</span><span class="token operator">=</span>cluster <span class="token parameter variable">--name</span> nginx-app <span class="token parameter variable">-p</span> <span class="token number">80</span>:80 nginx
kubectl run <span class="token parameter variable">--image</span><span class="token operator">=</span>nginx nginx-app <span class="token parameter variable">--port</span><span class="token operator">=</span><span class="token number">80</span> <span class="token parameter variable">--env</span><span class="token operator">=</span><span class="token string">&quot;DOMAIN=cluster&quot;</span>
<span class="token comment"># &#x67E5;&#x770B;&#x547D;&#x4EE4;</span>
<span class="token function">docker</span> <span class="token function">ps</span>
kubectl get pods
<span class="token comment"># &#x8FDE;&#x63A5;&#x5BB9;&#x5668;</span>
<span class="token function">docker</span> attach container-id
kubectl attach <span class="token parameter variable">-it</span> pod-name
<span class="token comment"># &#x5BB9;&#x5668;&#x4E2D;&#x6267;&#x884C;&#x547D;&#x4EE4;</span>
<span class="token function">docker</span> <span class="token builtin class-name">exec</span> container-id <span class="token function">cat</span> /etc/hostname
kubectl <span class="token builtin class-name">exec</span> pod-name -- <span class="token function">cat</span> /etc/hostname
<span class="token comment"># &#x6267;&#x884C;&#x4EA4;&#x4E92;&#x5F0F;&#x547D;&#x4EE4;</span>
<span class="token function">docker</span> <span class="token builtin class-name">exec</span> container-id /bin/bash
kubectl <span class="token builtin class-name">exec</span> pod-name -- /bin/bash
<span class="token comment"># &#x67E5;&#x770B;&#x65E5;&#x5FD7;</span>
<span class="token function">docker</span> logs <span class="token parameter variable">-f</span> container-id
kubectl logs <span class="token parameter variable">-f</span> pod-name
<span class="token comment"># &#x505C;&#x6B62;&#x548C;&#x5220;&#x9664;&#x5BB9;&#x5668;&#xFF1B;k8s&#x4E0D;&#x76F4;&#x63A5;&#x5173;&#x95ED;pod&#xFF0C;&#x800C;&#x662F;&#x5220;&#x9664;&#x62E5;&#x6709;&#x8BE5;pod&#x7684;Deployment&#xFF0C;pod&#x4F1A;&#x81EA;&#x52A8;&#x5220;&#x9664;</span>
<span class="token function">docker</span> stop container-id
<span class="token function">docker</span> <span class="token function">rm</span> containe
</code></pre>
<h3 id="&#x547D;&#x540D;&#x7A7A;&#x95F4;"><a name="&#x547D;&#x540D;&#x7A7A;&#x95F4;" class="anchor-navigation-ex-anchor" href="#&#x547D;&#x540D;&#x7A7A;&#x95F4;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.2. &#x547D;&#x540D;&#x7A7A;&#x95F4;</h3>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x521B;&#x5EFA;&#x547D;&#x540D;&#x7A7A;&#x95F4;</span>
kubectl create ns kube-test
<span class="token comment"># &#x83B7;&#x53D6;&#x547D;&#x540D;&#x7A7A;&#x95F4;</span>
kubectl get ns
kubectl get ns kube-test
kubectl get ns kube-test <span class="token parameter variable">-o</span> wide/json/yaml
kubectl describe ns kube-test
<span class="token comment"># &#x83B7;&#x53D6;&#x5F53;&#x524D; context</span>
kubectl config curret-context
<span class="token comment"># &#x5207;&#x6362;&#x5230; test-ns</span>
kubectl config set-context <span class="token parameter variable">--current</span> <span class="token parameter variable">--namespace</span><span class="token operator">=</span>kube-test
<span class="token comment"># &#x5220;&#x9664;&#x547D;&#x540D;&#x7A7A;&#x95F4;</span>
kubectl delete ns kube-test
</code></pre>
<h3 id="kubectl-&#x4E0A;&#x4E0B;&#x6587;&#x548C;&#x914D;&#x7F6E;"><a name="kubectl-&#x4E0A;&#x4E0B;&#x6587;&#x548C;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#kubectl-&#x4E0A;&#x4E0B;&#x6587;&#x548C;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.3. kubectl &#x4E0A;&#x4E0B;&#x6587;&#x548C;&#x914D;&#x7F6E;</h3>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x663E;&#x793A;&#x5408;&#x5E76;&#x540E;&#x7684; kubeconfig &#x914D;&#x7F6E;</span>
kubectl config view
<span class="token comment"># &#x540C;&#x65F6;&#x4F7F;&#x7528;&#x591A;&#x4E2A; kubeconfig &#x6587;&#x4EF6;&#x67E5;&#x770B;&#x5408;&#x5E76;&#x540E;&#x7684;&#x914D;&#x7F6E;</span>
<span class="token assign-left variable">KUBECONFIG</span><span class="token operator">=~</span>/.kube/config:~/.kube/kubconfig2 kubectl config view
<span class="token comment"># &#x83B7;&#x53D6; e2e &#x7528;&#x6237;&#x7684;&#x5BC6;&#x7801;</span>
kubectl config view <span class="token parameter variable">-o</span> <span class="token assign-left variable">jsonpath</span><span class="token operator">=</span><span class="token string">&apos;{.users[?(@.name == &quot;e2e&quot;)].user.password}&apos;</span>
<span class="token comment"># &#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x4E0A;&#x4E0B;&#x6587;&#x4E3A; my-cluster-name</span>
kubectl config use-context my-cluster-name
<span class="token comment"># &#x663E;&#x793A;&#x5F53;&#x524D;&#x7684;&#x4E0A;&#x4E0B;&#x6587;</span>
kubectl config current-context
<span class="token comment"># &#x4F7F;&#x7528;&#x6307;&#x5B9A;&#x7684;&#x7528;&#x6237;&#x548C; namespace &#x8BBE;&#x7F6E;&#x4E0A;&#x4E0B;&#x6587;</span>
kubectl config set-context context-text <span class="token parameter variable">--namespace</span><span class="token operator">=</span>kube-test <span class="token parameter variable">--cluster</span><span class="token operator">=</span>kubernetes <span class="token parameter variable">--user</span><span class="token operator">=</span>kubernetes-admin
kubectl config set-context gce <span class="token parameter variable">--user</span><span class="token operator">=</span>cluster-admin <span class="token parameter variable">--namespace</span><span class="token operator">=</span>foo <span class="token operator">&amp;&amp;</span> kubectl config use-context gce
</code></pre>
<h3 id="&#x521B;&#x5EFA;&#x5BF9;&#x8C61;"><a name="&#x521B;&#x5EFA;&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#&#x521B;&#x5EFA;&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4. &#x521B;&#x5EFA;&#x5BF9;&#x8C61;</h3>
<p>Kubernetes &#x7684;&#x6E05;&#x5355;&#x6587;&#x4EF6;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; json &#x6216; yaml &#x683C;&#x5F0F;&#x5B9A;&#x4E49;</p>
<p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>.yaml</code> <code>.yml</code> <code>.json</code> &#x4E3A;&#x6269;&#x5C55;&#x540D;</p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x521B;&#x5EFA;&#x8D44;&#x6E90;</span>
kubectl create <span class="token parameter variable">-f</span> ./my-manifest.yaml
<span class="token comment"># &#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x6587;&#x4EF6;&#x521B;&#x5EFA;&#x8D44;&#x6E90;</span>
kubectl create <span class="token parameter variable">-f</span> ./my1.yaml <span class="token parameter variable">-f</span> ./my2.yaml
<span class="token comment"># &#x4F7F;&#x7528;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x6E05;&#x5355;&#x6587;&#x4EF6;&#x521B;&#x5EFA;&#x8D44;&#x6E90;</span>
kubectl create <span class="token parameter variable">-f</span> ./dir
<span class="token comment"># &#x4F7F;&#x7528; url &#x6765;&#x521B;&#x5EFA;&#x8D44;&#x6E90;</span>
kubectl create <span class="token parameter variable">-f</span> https://git.io.vPieo
<span class="token comment"># &#x542F;&#x52A8;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;</span>
kubectl run nginx-test <span class="token parameter variable">--image</span><span class="token operator">=</span>nginx
<span class="token comment"># &#x83B7;&#x53D6; pod &#x548C; svc &#x7684;&#x6587;&#x6863;</span>
kubectl explain pod,svc
</code></pre>
<h3 id="&#x663E;&#x793A;&#x548C;&#x67E5;&#x627E;&#x8D44;&#x6E90;"><a name="&#x663E;&#x793A;&#x548C;&#x67E5;&#x627E;&#x8D44;&#x6E90;" class="anchor-navigation-ex-anchor" href="#&#x663E;&#x793A;&#x548C;&#x67E5;&#x627E;&#x8D44;&#x6E90;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.5. &#x663E;&#x793A;&#x548C;&#x67E5;&#x627E;&#x8D44;&#x6E90;</h3>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x5217;&#x51FA;&#x6240;&#x6709; namespace &#x4E2D;&#x7684;&#x6240;&#x6709; service</span>
kubectl get services
<span class="token comment"># &#x5217;&#x51FA;&#x6240;&#x6709; namespace &#x4E2D;&#x7684;&#x6240;&#x6709; pod</span>
kubectl get pods <span class="token parameter variable">-A</span>
kubectl get pods --all-namespace
<span class="token comment"># &#x5217;&#x51FA;&#x6240;&#x6709; pod &#x5E76;&#x663E;&#x793A;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;</span>
kubectl get pods <span class="token parameter variable">-o</span> wide
<span class="token comment"># &#x67E5;&#x770B;&#x6240;&#x6709;&#x7684; deployment</span>
kubectl get deploy <span class="token parameter variable">-A</span>
kubectl get deploy --all-namespace
<span class="token comment"># &#x5217;&#x51FA;&#x6307;&#x5B9A; deployment</span>
kubectl get deployment my-dep
<span class="token comment"># &#x5217;&#x51FA;&#x8BE5; namespace &#x4E2D;&#x7684;&#x6240;&#x6709; pod &#x5305;&#x62EC;&#x672A;&#x521D;&#x59CB;&#x5316;&#x7684;</span>
kubectl get pods --include-uninitialized
<span class="token comment"># &#x4F7F;&#x7528;&#x8BE6;&#x7EC6;&#x8F93;&#x51FA;&#x6765;&#x63CF;&#x8FF0;&#x547D;&#x4EE4;</span>
kubectl describe nodes my-nodes
kubectl describe pods my-pod
kubectl get <span class="token function">service</span> --sort-by<span class="token operator">=</span>.metadata.name
</code></pre>
<h3 id="&#x5220;&#x9664;&#x8D44;&#x6E90;"><a name="&#x5220;&#x9664;&#x8D44;&#x6E90;" class="anchor-navigation-ex-anchor" href="#&#x5220;&#x9664;&#x8D44;&#x6E90;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.6. &#x5220;&#x9664;&#x8D44;&#x6E90;</h3>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x5220;&#x9664; pod.json &#x6587;&#x4EF6;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x578B;&#x548C;&#x547D;&#x540D;&#x7684; pod</span>
kubectl delete <span class="token parameter variable">-f</span> ./pod.json
<span class="token comment"># &#x5220;&#x9664;&#x540D;&#x79F0;&#x5206;&#x522B;&#x4E3A; baz,foo &#x7684; pod,service</span>
kubectl delete pod,service baz foo
<span class="token comment"># &#x5220;&#x9664;&#x5177;&#x6709; name=myLabel &#x6807;&#x7B7E;&#x7684; pod &#x548C; service</span>
kubectl delete pods,services <span class="token parameter variable">-l</span> <span class="token assign-left variable">name</span><span class="token operator">=</span>myLabel
<span class="token comment"># &#x5220;&#x9664;&#x5177;&#x6709; name=myLabel &#x6807;&#x7B7E;&#x7684; pod &#x548C; service&#xFF0C;&#x5305;&#x62EC;&#x5C1A;&#x672A;&#x521D;&#x59CB;&#x5316;&#x7684;</span>
kubectl delete pods,services <span class="token parameter variable">-l</span> <span class="token assign-left variable">name</span><span class="token operator">=</span>myLabel --include-uninitalized
<span class="token comment"># &#x5220;&#x9664; my-ns namespace &#x4E0B;&#x7684;&#x6240;&#x6709; pod &#x548C; service&#xFF0C;&#x5305;&#x62EC;&#x5C1A;&#x672A;&#x521D;&#x59CB;&#x5316;&#x7684;</span>
kubectl <span class="token parameter variable">-n</span> my-ns delete po,svc <span class="token parameter variable">--all</span>
</code></pre>
<h3 id="&#x8D44;&#x6E90;&#x7C7B;&#x578B;"><a name="&#x8D44;&#x6E90;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x8D44;&#x6E90;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.7. &#x8D44;&#x6E90;&#x7C7B;&#x578B;</h3>
<p>&#x4E0B;&#x8868;&#x5217;&#x51FA;&#x7684;&#x662F; kubernetes &#x4E2D;&#x6240;&#x6709;&#x652F;&#x6301;&#x7684;&#x7C7B;&#x578B;&#x548C;&#x7F29;&#x5199;&#x7684;&#x522B;&#x540D;</p>
<table>
<thead>
<tr>
<th>&#x8D44;&#x6E90;&#x7C7B;&#x578B;</th>
<th>&#x7F29;&#x5199;&#x522B;&#x540D;</th>
</tr>
</thead>
<tbody>
<tr>
<td>clusters</td>
<td>-</td>
</tr>
<tr>
<td>cmponentstatuses</td>
<td>cs</td>
</tr>
<tr>
<td>configmaps</td>
<td>cm</td>
</tr>
<tr>
<td>daemonsets</td>
<td>ds</td>
</tr>
<tr>
<td>daemonsets</td>
<td>ds</td>
</tr>
<tr>
<td>deployments</td>
<td>deploy</td>
</tr>
<tr>
<td>endpoints</td>
<td>ep</td>
</tr>
<tr>
<td>event</td>
<td>ev</td>
</tr>
<tr>
<td>horizontalpodautoscalers</td>
<td>hpa</td>
</tr>
<tr>
<td>ingresses</td>
<td>ing</td>
</tr>
<tr>
<td>jobs</td>
<td>-</td>
</tr>
<tr>
<td>limitranges</td>
<td>limits</td>
</tr>
<tr>
<td>namespaces</td>
<td>ns</td>
</tr>
<tr>
<td>networkpolicies</td>
<td>-</td>
</tr>
<tr>
<td>nodes</td>
<td>no</td>
</tr>
<tr>
<td>statefulesets</td>
<td>-</td>
</tr>
<tr>
<td>presistentvolumeclaims</td>
<td>pvc</td>
</tr>
<tr>
<td>persistentvolumes</td>
<td>pv</td>
</tr>
<tr>
<td>pods</td>
<td>po</td>
</tr>
<tr>
<td>podsecuritypolicies</td>
<td>psp</td>
</tr>
<tr>
<td>podtemplates</td>
<td>-</td>
</tr>
<tr>
<td>replicationcontrollers</td>
<td>rc</td>
</tr>
<tr>
<td>resourcequotas</td>
<td>quota</td>
</tr>
<tr>
<td>cronjob</td>
<td>-</td>
</tr>
<tr>
<td>secrets</td>
<td>-</td>
</tr>
<tr>
<td>serviceaccount</td>
<td>sa</td>
</tr>
<tr>
<td>services</td>
<td>svc</td>
</tr>
<tr>
<td>storageclasses</td>
<td>-</td>
</tr>
<tr>
<td>thirdpartyresources</td>
<td>-</td>
</tr>
</tbody>
</table>
<h2 id="&#x63A7;&#x5236;&#x5668;"><a name="&#x63A7;&#x5236;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x63A7;&#x5236;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. &#x63A7;&#x5236;&#x5668;</h2>
<h3 id="rcrs"><a name="rcrs" class="anchor-navigation-ex-anchor" href="#rcrs"><i class="fa fa-link" aria-hidden="true"></i></a>1.6.1. RC/RS</h3>
<p>ReplicationController(RC) &#x7528;&#x6765;&#x786E;&#x4FDD;&#x5BB9;&#x5668;&#x5E94;&#x7528;&#x7684;&#x526F;&#x672C;&#x6570;&#x59CB;&#x7EC8;&#x4FDD;&#x6301;&#x5728;&#x7528;&#x6237;&#x5B9A;&#x4E49;&#x7684;&#x526F;&#x672C;&#x6570;&#xFF1A;&#x5F02;&#x5E38;&#x9000;&#x51FA;&#x81EA;&#x52A8;&#x521B;&#x5EFA;&#x65B0;&#x7684; Pod &#x5E76;&#x56DE;&#x6536;&#x591A;&#x51FA;&#x7684;&#x5BB9;&#x5668;</p>
<p>ReplicaSet(RS) &#x662F; RC &#x7684;&#x5347;&#x7EA7;&#x7248;&#xFF0C;&#x652F;&#x6301;&#x96C6;&#x5408;&#x5F0F;&#x7684; selector&#xFF0C;&#x4E00;&#x822C;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528; Deployment &#x7BA1;&#x7406; ReplicaSet</p>
<blockquote>
<p>ReplicaSet &#x793A;&#x4F8B;</p>
</blockquote>
<pre class="language-"><code class="lang-yaml"><span class="token comment"># &#x6307;&#x5B9A;&#x4F7F;&#x7528;&#x7684; API &#x7248;&#x672C;</span>
<span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> apps/v1
<span class="token comment"># &#x6307;&#x5B9A;&#x8D44;&#x6E90;&#x7C7B;&#x578B;</span>
<span class="token key atrule">kind</span><span class="token punctuation">:</span> ReplicaSet
<span class="token comment"># &#x6DFB;&#x52A0;&#x5143;&#x6570;&#x636E;&#xFF0C;&#x5305;&#x62EC;&#x540D;&#x79F0;&#x548C;&#x6807;&#x7B7E;</span>
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token comment"># &#x540D;&#x79F0;</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>replicaset
  <span class="token comment"># &#x6807;&#x7B7E;</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>app
<span class="token comment"># &#x5B9A;&#x4E49;&#x89C4;&#x8303;</span>
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token comment"># &#x6307;&#x5B9A;&#x8981;&#x7EF4;&#x62A4;&#x7684; pod &#x526F;&#x672C;&#x6570;&#x91CF;</span>
  <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">3</span>
  <span class="token comment"># &#x5B9A;&#x4E49;&#x5982;&#x4F55;&#x9009;&#x62E9;&#x8981;&#x7BA1;&#x7406;&#x7684; pod</span>
  <span class="token key atrule">selector</span><span class="token punctuation">:</span>
    <span class="token comment"># &#x6307;&#x5B9A;&#x8981;&#x9009;&#x62E9;&#x7684; pod &#x6807;&#x7B7E;&#xFF0C;&#x4E0E; pod &#x6A21;&#x7248;&#x7684;&#x6807;&#x7B7E;&#x5339;&#x914D;</span>
    <span class="token key atrule">matchLabels</span><span class="token punctuation">:</span>
      <span class="token key atrule">app</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>app
  <span class="token comment"># &#x5B9A;&#x4E49;&#x6A21;&#x7248;</span>
  <span class="token key atrule">template</span><span class="token punctuation">:</span>
    <span class="token comment"># &#x5305;&#x542B; pod &#x6A21;&#x677F;&#x7684;&#x5143;&#x6570;&#x636E;</span>
    <span class="token key atrule">metadata</span><span class="token punctuation">:</span>
      <span class="token comment"># &#x6807;&#x7B7E;&#xFF0C;&#x7528;&#x4E8E;&#x5173;&#x8054; pod &#x4E0E; ReplicaSet</span>
      <span class="token key atrule">labels</span><span class="token punctuation">:</span>
        <span class="token key atrule">app</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>app
    <span class="token comment"># &#x5B9A;&#x4E49;&#x8981;&#x521B;&#x5EFA;&#x7684; pod &#x7684;&#x89C4;&#x8303;</span>
    <span class="token key atrule">spec</span><span class="token punctuation">:</span>
      <span class="token comment"># &#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x914D;&#x7F6E;</span>
      <span class="token key atrule">containers</span><span class="token punctuation">:</span>
        <span class="token comment"># &#x5BB9;&#x5668;&#x540D;&#x79F0;</span>
        <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>container
          <span class="token comment"># &#x5BB9;&#x5668;&#x4F7F;&#x7528;&#x955C;&#x50CF;</span>
          <span class="token key atrule">image</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>image<span class="token punctuation">:</span>latest
          <span class="token comment"># &#x5BB9;&#x5668;&#x76D1;&#x542C;&#x7684;&#x7AEF;&#x53E3;</span>
          <span class="token key atrule">ports</span><span class="token punctuation">:</span>
            <span class="token punctuation">-</span> <span class="token key atrule">containerPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
</code></pre>
<h3 id="deployment"><a name="deployment" class="anchor-navigation-ex-anchor" href="#deployment"><i class="fa fa-link" aria-hidden="true"></i></a>1.6.2. Deployment</h3>
<p>Deployment &#x4E3A; Pod &#x548C; ReplicaSet &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x58F0;&#x660E;&#x5F0F;&#x5B9A;&#x4E49;&#xFF08;declarative&#xFF09;&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x6765;&#x66FF;&#x4EE3; RC/RS &#x6765;&#x65B9;&#x4FBF;&#x7684;&#x7BA1;&#x7406;&#x5E94;&#x7528;&#x3002;&#x5178;&#x578B;&#x7684;&#x5E94;&#x7528;&#x573A;&#x666F;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>&#x5B9A;&#x4E49; Deployment &#x6765;&#x521B;&#x5EFA; Pod &#x548C; ReplicaSet</li>
<li>&#x6EDA;&#x52A8;&#x5347;&#x7EA7;&#x548C;&#x56DE;&#x6EDA;&#x5E94;&#x7528;</li>
<li>&#x6269;&#x5BB9;&#x548C;&#x6240;&#x5BB9;</li>
<li>&#x6682;&#x505C;&#x548C;&#x7EE7;&#x7EED; Deployment</li>
</ul>
<blockquote>
<p>Deployment &#x793A;&#x4F8B;</p>
</blockquote>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> extensions/v1beta1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Deployment
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx<span class="token punctuation">-</span>deployment
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">3</span>
  <span class="token key atrule">template</span><span class="token punctuation">:</span>
    <span class="token key atrule">metadata</span><span class="token punctuation">:</span>
      <span class="token key atrule">labels</span><span class="token punctuation">:</span>
        <span class="token key atrule">app</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">spec</span><span class="token punctuation">:</span>
      <span class="token key atrule">containers</span><span class="token punctuation">:</span>
        <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
          <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx<span class="token punctuation">:</span>1.7.9
          <span class="token key atrule">ports</span><span class="token punctuation">:</span>
            <span class="token punctuation">-</span> <span class="token key atrule">containerPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
</code></pre>
<blockquote>
<p>&#x6267;&#x884C;&#x547D;&#x4EE4;</p>
</blockquote>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x6269;&#x5BB9;</span>
kubectl scale deployment nginx-deployment <span class="token parameter variable">--replicas</span> <span class="token number">10</span>
<span class="token comment"># &#x8BBE;&#x7F6E;&#x81EA;&#x52A8;&#x6269;&#x5BB9;</span>
kubectl autoscale deployment nginx-deployment <span class="token parameter variable">-min</span> <span class="token number">10</span> <span class="token parameter variable">-max</span> <span class="token number">15</span> --cpu-percent <span class="token number">80</span>
<span class="token comment"># &#x66F4;&#x65B0;&#x955C;&#x50CF;</span>
kubectl <span class="token builtin class-name">set</span> image deployment/nginx-deployment nginx nginx:1.9.1
<span class="token comment"># &#x56DE;&#x6EDA;</span>
kubectl rollout undo deployment/nginx-deployment
</code></pre>
<h2 id="kubernetes-&#x5E94;&#x7528;"><a name="kubernetes-&#x5E94;&#x7528;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x5E94;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. Kubernetes &#x5E94;&#x7528;</h2>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x521B;&#x5EFA;&#x5E94;&#x7528;</span>
kubectl run net-test <span class="token parameter variable">--image</span><span class="token operator">=</span>alphine <span class="token parameter variable">--replicas</span><span class="token operator">=</span><span class="token number">1</span> <span class="token function">sleep</span> <span class="token number">3600</span>
<span class="token comment"># &#x67E5;&#x770B;pod&#x8FD0;&#x884C;&#x5728;&#x54EA;&#x4E2A;&#x8282;&#x70B9;&#x4E0A;</span>
kubectl get pods <span class="token parameter variable">-o</span> wide
<span class="token comment"># &#x67E5;&#x770B;</span>
kubectl get deployment net-test
kubectl describe deployment net-test

kubectl create deployment net-test2 <span class="token parameter variable">--image</span><span class="token operator">=</span>alphine <span class="token parameter variable">--replicas</span><span class="token operator">=</span><span class="token number">1</span>
</code></pre>
<h2 id="ingress"><a name="ingress" class="anchor-navigation-ex-anchor" href="#ingress"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. Ingress</h2>
<p><a href="https://matthewpalmer.net/kubernetes-app-developer/articles/kubernetes-ingress-guide-nginx-example.html" target="_blank">Ingress &#x793A;&#x4F8B;&#x8BF4;&#x660E;</a></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># &#x5B89;&#x88C5; Ingress</span>
kubectl apply <span class="token parameter variable">-f</span> https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.0/deploy/static/provider/cloud/deploy.yaml
kubectl apply <span class="token parameter variable">-f</span> https://github.com/kubernetes/ingress-nginx/blob/controller-v1.2.0/deploy/static/provider/cloud/deploy.yaml
kubectl apply <span class="token parameter variable">-f</span> deploy.yaml
<span class="token comment"># &#x9A8C;&#x8BC1;</span>
kubectl get pods --all-namespaces <span class="token parameter variable">-l</span> app.kubernetes.io/name<span class="token operator">=</span>ingress-nginx
kubectl get pods <span class="token parameter variable">-n</span> ingress-nginx
</code></pre>
<h2 id="&#x53C2;&#x8003;&#x6587;&#x6863;"><a name="&#x53C2;&#x8003;&#x6587;&#x6863;" class="anchor-navigation-ex-anchor" href="#&#x53C2;&#x8003;&#x6587;&#x6863;"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. &#x53C2;&#x8003;&#x6587;&#x6863;</h2>
<blockquote>
<p>windows &#x5355;&#x673A;&#x642D;&#x5EFA; k8s &#x73AF;&#x5883;</p>
</blockquote>
<p><a href="https://cloud.tencent.com/developer/article/1797416" target="_blank">https://cloud.tencent.com/developer/article/1797416</a></p>
<blockquote>
<p>Desktop &#x5BF9;&#x5E94; kubernetes &#x6267;&#x884C;&#x811A;&#x672C;</p>
</blockquote>
<p><a href="https://gitee.com/magiboy/k8s-for-docker-desktop" target="_blank">https://gitee.com/magiboy/k8s-for-docker-desktop</a></p>
<blockquote>
<p>kubernetes &#x57FA;&#x7840;&#x6559;&#x7A0B;</p>
</blockquote>
<p><a href="https://lib.jimmysong.io/kubernetes-handbook/" target="_blank">https://lib.jimmysong.io/kubernetes-handbook/</a></p>
<blockquote>
<p>kubernetes &#x968F;&#x7B14;</p>
</blockquote>
<p><a href="https://www.cnblogs.com/linuxk/category/1248289.html?page=2" target="_blank">https://www.cnblogs.com/linuxk/category/1248289.html?page=2</a></p>
<blockquote>
<p>wsl &#x5168;&#x5C40;&#x914D;&#x7F6E;</p>
</blockquote>
<p><a href="https://dowww.spencerwoo.com/4-advanced/4-3-wslconfig.html" target="_blank">https://dowww.spencerwoo.com/4-advanced/4-3-wslconfig.html</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../tool/gradle.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: Gradle">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Kubernetes","level":"1.6.5","depth":2,"previous":{"title":"Gradle","level":"1.6.4","depth":2,"path":"markdown/tool/gradle.md","ref":"markdown/tool/gradle.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-default","prism","-highlight","search-pro","-search","-lunr","expandable-chapters-small","splitter","-sharing","anchor-navigation-ex","code"],"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"},"pluginsConfig":{"prism":{},"search-pro":{},"expandable-chapters-small":{},"splitter":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"theme":"default","author":"chenjiebin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pluginConfig":{"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"anchor-navigation-ex":{"showLevel":true},"theme-default":{"toggleMenu":false}},"variables":{},"title":"GitBook笔记","gitbook":"*","description":"学习笔记，包含前后端基础知识及框架的学习笔记"},"file":{"path":"markdown/framework/kubernate.md","mtime":"2023-12-21T02:43:49.364Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-02-28T09:32:04.838Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

